<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/pages/common/taglib.jsp"%>
<%@ include file="/WEB-INF/pages/common/back-common.jsp"%>
<%@ include file="/WEB-INF/pages/common/jquery2.1.4.jsp"%>
<%@ include file="/WEB-INF/pages/common/back-dialog.jsp"%>
<html>
    <head>
        <title>创建</title>
<script type='text/javascript' src="<ls:templateResource item='/resources/common/js/jquery.validate.js'/>" ></script>
<link rel="stylesheet" type="text/css" media="screen" href="${contextPath}/resources/common/css/errorform.css" />
<link href="<ls:templateResource item='/resources/plugins/select2-4.0/select2.css'/>" rel="stylesheet"/>
<script src="<ls:templateResource item='/resources/plugins/select2-4.0/select2.full.min.js'/>" type="text/javascript"></script>
<script src="<ls:templateResource item='/resources/plugins/select2-4.0/i18n/zh-CN.js'/>" type="text/javascript"></script>
<script src="<ls:templateResource item='/resources/plugins/select2-4.0/makeSelect2.js'/>" type="text/javascript"></script>
<link rel="stylesheet" href="<ls:templateResource item='/resources/plugins/kindeditor/themes/default/default.css'/>"/>
<link rel="stylesheet" href="<ls:templateResource item='/resources/plugins/kindeditor/plugins/code/prettify.css'/>"/>
<script charset="utf-8" src="<ls:templateResource item='/resources/plugins/kindeditor/kindeditor-min.js'/>"></script>
<script charset="utf-8" src="<ls:templateResource item='/resources/plugins/kindeditor/lang/zh_CN.js'/>"></script>
<script charset="utf-8" src="<ls:templateResource item='/resources/plugins/kindeditor/plugins/code/prettify.js'/>"></script>
        <script language="javascript">
		    $.validator.setDefaults({
		    });
		  var  contextPath = '${contextPath}';
		    $(document).ready(function() {
		   // parent.closeDropdown(); //再执行关闭   	
		    jQuery("#form1").validate({
		            rules: {
		            userId: {
		                required: true,
		            }
		        },
		        messages: {
		        	userId: {
		                required: "请选择组员"
		            }
		        }
		    });
 
		//斑马条纹
     	 $("#col1 tr:nth-child(even)").addClass("even");
     	makeSelect2(contextPath + "/admin/adminUser/userListInTeam/${task.projectId}","#userName","项目成员","value","key");
     	
     	 //binding Submit
   	 $("#Submit").click(function(){
   		 //关键所在，同步输入的值到textarea中
   	 newsKindEditor .sync();
   	 if($("#form1").valid()){
   	 var formData = $("#form1").serialize();
   	   $.ajax({
          type: 'post', // 提交方式 get/post
          url:  "${contextPath}/admin/task/assignUpdateTask/${task.id}", // 需要提交的 url
          data: formData,
          dataType : 'json', 
          error: function(jqXHR, textStatus, errorThrown) {
   	 		 layer.alert("保存失败" + textStatus);
   		},
          success: function(data) { // data 保存提交后返回的数据，一般为 json 数据
              // 此处可对 data 作相关处理
              if("success" == data){
                layer.msg("保存成功");
                closeDialog();
              }else{
            	  layer.msg("保存失败");
              }
            
          }
      });
      return false; // 阻止表单自动提交事件
   	};
   	});
     	 
     	 
     KindEditor.options.filterMode = false;
     var newsKindEditor = KindEditor.create('textarea[name="remark"]', {
         cssPath: '${contextPath}/resources/plugins/kindeditor/plugins/code/prettify.css',
         uploadJson: '${contextPath}/editor/uploadJson/upload;jsessionid=${cookie.JSESSIONID.value}',
         fileManagerJson: '${contextPath}/editor/uploadJson/fileManager',
         allowFileManager: true,
         width: '100%',
         height: '200px',
         items : [
				'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
				'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
				'insertunorderedlist', '|', 'emoticons', 'link']
     });
     	
});
    
	function closeDialog(){
		var index = parent.layer.getFrameIndex("assignTask"); //先得到当前iframe层的索引
		parent.layer.close(index); //再执行关闭   
		if(parent.sendData){
			parent.sendData();//异步
		}else{
			//parent.location.reload();
		}
	}
	
	function cancelDialog(){
		var index = parent.layer.getFrameIndex("assignTask"); //先得到当前iframe层的索引
		parent.layer.close(index); //再执行关闭   
		if(parent.sendData){
			parent.sendData();
		}
	}
</script>
</head>
    <body>
        <form method="post" id="form1">
            <input id="id" name="id" value="${projectMember.id}" type="hidden">
            <input id="projectId" name="projectId" value="${projectId}" type="hidden">
            <div align="center">
            <table border="0" align="center" class="${tableclass}" id="col1" style="width: 100%">
                <thead>
                    <tr class="sortable">
                        <th colspan="2">
                            <div align="center">
                                	分配目标
                            </div>
                        </th>
                    </tr>
                </thead>
			<tr>
		        <td>
		          	指派给: <font color="ff0000">*</font>
		       	</td>
		        <td>
		            <select name="userName" id="userName" style="width: 200px">
					   <c:if test="${not empty task.assignedto}">
					   	  <option value="${task.assignedto}">${task.assignedtoRealName}</option>
					   	</c:if>
				   </select>
		        </td>
			</tr>
			<tr>
		        <td>
		          	预计剩余: 
		       	</td>
		        <td>
		        	<input type="text" id="leftHours" name="leftHours" size="10" value="${task.leftHours}"/>小时
		        </td>
			</tr>
			<tr>
		        <td>
		          	备注
		       	</td>
		        <td>
		           <textarea name="remark" id="remark" cols="100" rows="8" style="width:700px;height:200px;visibility:hidden;">${task.remark}</textarea>
		        </td>
			</tr>
			<tr>
		        <td>
		          	历史记录
		       	</td>
		        <td>
		      		<c:forEach items="${requestScope.list}" var = "event">
				          <div class="group-item">
				         		 <span id="index-index" class="priv">${event.title} 
				         		 <c:if test="${not empty event.relateData}">
				         		     <span data="${event.relateData}" class="relateData">+</span>
				         		 </c:if>
				         		  </span>
				          </div>
				  	</c:forEach>
		        </td>
			</tr>
                <tr>
                    <td colspan="2">
                        <div align="center">
                             <input type="button" name="Submit" id="Submit"  value="提交" />
                            <input type="button" value="关闭" onclick="javascript:cancelDialog()" />
                        </div>
                    </td>
                </tr>
            </table>
           </div>
        </form>
        <script type="text/javascript">
        	$(".relateData").hover(function(){
        		var data=$(this).attr("data");
        		layer.tips(data, $(this), {
        			  tips: [1, '#3595CC'],
        			  time: 40000
        			});
        	},function(){
        		layer.closeAll('tips'); //关闭所有的tips层 
        	});
        </script>
    </body>
</html>

